package dtd.PHS.VND_ExchangeRate;

import dtd.PHS.VND_ExchangeRate.data.DataProvider;
import dtd.PHS.VND_ExchangeRate.data.IDelegateDataGetter;
import dtd.PHS.VND_ExchangeRate.ui.gesture.GestureActivity;
import dtd.PHS.VND_ExchangeRate.utils.Logger;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public abstract class NeedUpdateActivity 
	extends GestureActivity 
	implements IDelegateDataGetter 
{

	private BroadcastReceiver updateRatesReceiver = new BroadcastReceiver() {		
		@Override
		public void onReceive(Context context, Intent intent) {
			Logger.logInfo("Broadcase intent catched !");
			requestRates();
		}
	};
	
	@Override
	protected void onResume() {	
		super.onResume();
		requestRates();
		IntentFilter filter = new IntentFilter();
		filter.addAction(getString(R.string.UPDATE_RATE_BROADCAST_INTENT));
		this.registerReceiver(this.updateRatesReceiver, filter);
	}

	@Override
	protected void onPause() {	
		super.onPause();
		this.unregisterReceiver(updateRatesReceiver);
	}
	private void requestRates() {
		DataProvider.getInstance().requestListRates( this );
	}
}
